using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 计算UI
/// </summary>
public class CalculatePanel : MonoBehaviour
{
   [SerializeField] private DynimacLogVC logVc;
   /// <summary>
   /// 计算速度
   /// </summary>
   [SerializeField] private Toggle compute_speed_u_Toggle;
   [SerializeField] private Toggle compute_speed_v__Toggle;
   [SerializeField] private Toggle compute_speed_w_Toggle;
   
   /// <summary>
   /// 计算热流密度
   /// </summary>
   [SerializeField] private Toggle compute_heat_x_Toggle;
   [SerializeField] private Toggle compute_heat_y_Toggle;
   [SerializeField] private Toggle compute_heat_z_Toggle;
   /// <summary>
   /// 计算温度
   /// </summary>
   [SerializeField] private Toggle compute_thermo_temp_Toggle;
   /// <summary>
   /// 计算压力
   /// </summary>
   [SerializeField] private Toggle compute_thermo_press_Toggle;
   /// <summary>
   /// 时间步长
   /// </summary>
   [SerializeField] private InputField time_step_Input;
   /// <summary>
   /// 计算步数
   /// </summary>
   [SerializeField] private InputField run_Input;

   /// <summary>
   /// 转换成可视模式按钮
   /// </summary>
   [SerializeField] private Button sendBtn;
   [SerializeField] private Button calculateBtn;
   
   [SerializeField] private Toggle dump_grid_number;
   [SerializeField] private Toggle dump_compute_speed_u_Toggle;
   [SerializeField] private Toggle dump_compute_speed_v_Toggle;
   [SerializeField] private Toggle dump_compute_speed_w_Toggle;
   [SerializeField] private Toggle dump_compute_thermo_temp_Toggle;
   [SerializeField] private Toggle dump_compute_thermo_press_Toggle;
   [SerializeField] private Toggle dump_compute_heat_Toggle;
   [SerializeField] private Toggle is_grid_coordinate_Toggle;
   
   /// <summary>
   /// 获取设置的计算速度
   /// </summary>
   /// <returns></returns>
   public string[] GetComputeSpeed()
   {
      List<string> list = new List<string>();
      if (compute_speed_u_Toggle.isOn)
      {
         list.Add("u");
      }
      if (compute_speed_v__Toggle.isOn)
      {
         list.Add("v");
      }
      if (compute_speed_w_Toggle.isOn)
      {
         list.Add("w");
      }
      return list.ToArray();
   }

   public void Start()
   {
      sendBtn.onClick.AddListener(OnConvertBtnClick);
      calculateBtn.onClick.AddListener(OnCalculateBtnClick);
   }

   public void OnConvertBtnClick()
   {
      
      // AirManager.instance.SetWebData();
      AirManager.instance.ConvertData();
   }

   public void OnCalculateBtnClick()
   {
      AirManager.instance.SendData();
   }
   /// <summary>
   /// 获取设置的计算热流密度
   /// </summary>
   /// <returns></returns>
   public string[] GetComputeHeat()
   {
      List<string> list = new List<string>();
      if (compute_heat_x_Toggle.isOn)
      {
         list.Add("heatx");
      }
      if (compute_heat_y_Toggle.isOn)
      {
         list.Add("heaty");
      }
      if (compute_heat_z_Toggle.isOn)
      {
         list.Add("heatz");
      }
      return list.ToArray();
   }
   
   /// <summary>
   /// 获取设置的计算热力学参数
   /// </summary>
   /// <returns></returns>
   public string[] GetComputeThermo()
   {
      List<string> list = new List<string>();
      if (compute_thermo_temp_Toggle.isOn)
      {
         list.Add("temp");
      }
      if (compute_thermo_press_Toggle.isOn)
      {
         list.Add("press");
      }
      return list.ToArray();
   }
   /// <summary>
   /// 获取设置的时间步长
   /// </summary>
   /// <returns></returns>
   public string GetTimeStep()
   {
      return time_step_Input.text;
   }
   /// <summary>
   /// 获取设置的计算步数
   /// </summary>
   /// <returns></returns>
   public string GetRun()
   {
      return run_Input.text;
   }
   /// <summary>
   /// 输出网格序号
   /// </summary>
   /// <returns></returns>
   public string GetDumpGridNumber()
   {
      return dump_grid_number.isOn ? "1" : "0";
   }
   /// <summary>
   /// 输出结果文档中的 多选 u、v、w
   /// </summary>
   /// <returns></returns>
   public string[] GetDumpComputeSpeedU()
   {
      List<string> list = new List<string>();
      if (dump_compute_speed_u_Toggle.isOn)
      {
         list.Add("u");
      }
      if (dump_compute_speed_v_Toggle.isOn)
      {
         list.Add("v");
      }
      if (dump_compute_speed_w_Toggle.isOn)
      {
         list.Add("w");
      }
      return list.ToArray();
   }
   /// <summary>
   ///  输出结果文档中的 多选 temp、press
   /// </summary>
   /// <returns></returns>
   public string[] GetDumpComputeThermo()
   {
      List<string> list = new List<string>();
      if (dump_compute_thermo_temp_Toggle.isOn)
      {
         list.Add("temp");
      }
      if (dump_compute_thermo_press_Toggle.isOn)
      {
         list.Add("press");
      }
      return list.ToArray();
   }
   /// <summary>
   /// 勾选热流量密度 则为true
   /// </summary>
   /// <returns></returns>
   public bool GetDumpComputeHeat()
   {
      return dump_compute_heat_Toggle.isOn;
   }
   /// <summary>
   /// // 勾选网格坐标 则为true
   /// </summary>
   /// <returns></returns>
   public bool GetIsGridCoordinate()
   {
      return is_grid_coordinate_Toggle.isOn;
   }
   public void AppendData(string log)
   {
      logVc.AppendData(log);
   }
}
